package com.htn.gallery.web.control;

import java.io.File;
import java.net.URL;

import com.google.gdata.client.photos.PicasawebService;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.media.MediaFileSource;
import com.google.gdata.data.photos.PhotoEntry;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ProcessPhotoAction extends ActionSupport {

	private File userImage;
	private String userImageContentType;
	private String userImageFileName;
	private String albumId;
	
	public String upload() {
		try {
			PicasawebService myService = new PicasawebService("exampleCo-exampleApp-1");
			myService.setUserCredentials("donghaiit@gmail.com", "Ocean1980");
			String url = "https://picasaweb.google.com/data/feed/api/user/donghaiit/albumid/" + albumId;
			System.out.println("*************" + albumId + "****************");
			URL albumPostUrl = new URL(url);
	
			PhotoEntry myPhoto = new PhotoEntry();
			myPhoto.setTitle(new PlainTextConstruct(userImageFileName));
			//myPhoto.setDescription(new PlainTextConstruct("Puppies are the greatest."));
	
			MediaFileSource myMedia = new MediaFileSource(userImage, userImageContentType);
			myPhoto.setMediaSource(myMedia);
	
			myService.insert(albumPostUrl, myPhoto);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return SUCCESS;
	}
	public File getUserImage() {
		return userImage;
	}
	public void setUserImage(File userImage) {
		this.userImage = userImage;
	}
	public String getUserImageContentType() {
		return userImageContentType;
	}
	public void setUserImageContentType(String userImageContentType) {
		this.userImageContentType = userImageContentType;
	}
	public String getUserImageFileName() {
		return userImageFileName;
	}
	public void setUserImageFileName(String userImageFileName) {
		this.userImageFileName = userImageFileName;
	}
	public String getAlbumId() {
		return albumId;
	}
	public void setAlbumId(String albumId) {
		this.albumId = albumId;
	}
}
